package com.umpay.config;

import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;


/**
 * @author zhanglz
 * @ClassName: AsyncInitConfig
 * @Description:
 * @date 2018/6/6 16:33
 */
public class AsyncInitConfig extends ThreadPoolTaskExecutor {

    final String mark = "ASYNC-";

    @Override
    public String nextThreadName() {
        String currentThreadName = Thread.currentThread().getName();
        String newThreadName = "";
        if(currentThreadName.indexOf(mark) > -1){
            newThreadName = currentThreadName.substring(0, currentThreadName.lastIndexOf(mark)+8) +
                    mark + AsyncThreadConfig.getFactory().getCurrentCount() + "-" +
                    currentThreadName.substring(currentThreadName.lastIndexOf(mark)+8);
        }else{
            newThreadName = mark + AsyncThreadConfig.getFactory().getCurrentCount() + "-" + currentThreadName;
        }
        return  newThreadName;
    }
}
